public class Solution482 {
    public String licenseKeyFormatting(String s, int k) {
        String[] temp = s.split("-");
        String str = "";
        for (int i = 0; i < temp.length; i++) {
            str += temp[i];
        }
        if(str.length()<k) return str;
        str = str.toUpperCase();
        String res = "";
        int m = str.length() / k;
        int left = str.length() % k;
        int local = 0;
        for (int i = 0; i < left; i++) {
            res += str.charAt(local);
            local++;
        }
        if(left!=0) res += "-";
        for (int i = 0; i < m - 1; i++) {
            for (int j = 0; j < k; j++) {
                res += str.charAt(local);
                local++;
            }
            res += "-";
        }
        for (int j = 0; j < k; j++) {
            res += str.charAt(local);
            local++;
        }
        return res;
    }

    public static void main(String[] args) {
        Solution482 solution482 = new Solution482();
        System.out.println(solution482.licenseKeyFormatting("2",2));
        System.out.println(solution482.licenseKeyFormatting("---",3));
    }
}
